
/**
 * An encapsulation for a laps of time,
 * with a beginning and a duration
 * @author J.J.G.
 */
package fr.emse.tatiana.display;


import java.util.*;

public class DisplayDate
{
	long beginTime;
	long duration;
	String beginDate;

	
	public DisplayDate()
	{
		Date cd = new Date();
		beginTime = cd.getTime();
		duration = 0;
		beginDate = null;
	}
	
	public DisplayDate(long v)
	{
		beginTime = v;
		duration = 0;
		beginDate = null;
	}

	public DisplayDate(long v, long d)
	{
		beginTime = v;
		duration = d;
		beginDate = null;
	}
	
	public DisplayDate(Date d)
	{
		beginTime = d.getTime();
		duration = 0;
		beginDate = null;
	}

	public DisplayDate(Date d1, Date d2)
	{
		beginTime = d1.getTime();
		duration = d2.getTime() - beginTime;
		if (duration < 0)
			duration = 0;
		beginDate = null;
	}

	public DisplayDate(Date d, long xduration)
	{
		beginTime = d.getTime();
		duration = xduration;
		if (duration < 0)
			duration = 0;
		beginDate = null;
	}

	public long getTime()
	{
		return beginTime;
	}

	public long getDuration()
	{
		return duration;
	}
	
	public String toXMLString()
	{
		return "<time><date>" + beginTime + "</date><duration>" + duration + "</duration></time>";
	}
	
	public String toInfo(String name)
	{
		return "<info \"" + name + "\">" + toXMLString() + "</info>" ;
	}
	
	@Override
	public String toString()
	{
		if (beginDate == null)
		{
			Date dt = new Date(beginTime);
			beginDate = dt.toString();
		}
		return beginDate;
	}
}

